# -*- coding: utf-8 -*-
class PurchaseReturned < ActiveRecord::Base
  has_many :purchase_returned_details ,:dependent => :destroy  #级联删除子表

  belongs_to :vendor
  belongs_to :employee      #制单人员
  belongs_to :department
  belongs_to :company

  belongs_to :purchase_order

  belongs_to :associate_auditor, :class_name => 'Employee', :foreign_key => 'associate_auditor_id'

  belongs_to :warehouse_employee, :class_name => 'Employee', :foreign_key => 'warehouse_employee_id'

  def self.findAllPurchaseReturneds  conditionsStr,conditionsHash,paramsHash
    begin
      find(
        :all,
        :conditions => [conditionsStr,conditionsHash],
        :include => [:employee,:department,:vendor,:associate_auditor,:warehouse_employee],
        :offset => paramsHash[:offset],
        :limit => paramsHash[:limit],
        :order => 'updated_at DESC'
      )
    rescue Exception => e
      logger.info e
    end
  end
  
  def self.countAllPurchaseReturneds  conditionsStr,conditionsHash
    count(
      :all,
      :conditions => [conditionsStr,conditionsHash]
      #:include=>[:employee,:department,:vendor,:associate_auditor,:warehouse_employee,:purchase_order]
    )
  end
end
